#!/usr/local/bin/python3

import string
import re
import urllib.request

def c0():
    print(2**38)

def c1():
    s = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."
    s2 = "map"
    """ my way
    result = ''
    print(s)
    for c in s:
        #tc = c
        if(c.isalpha()):
            
            c = chr((ord(c) - 97 + 2) % 26 + 97)
        result += c
    print(result)
    """
    table = str.maketrans(string.ascii_lowercase, string.ascii_lowercase[2:] + string.ascii_lowercase[:2])
    s = s.translate(table)
    
    print(s)

def c2():
    

    text = ''.join([line.rstrip() for line in open("resources/orc.txt")])

    
    
    result = ''
    for c in text:
        if(c.isalpha()):
            result += c

    print(result)

def c3():
    txt = ''.join([line.rstrip() for line in open("resources/re.txt")])

    result = ''
    """ my way
    i = 0
    while(i < len(txt)):
        if(i < 3):
            i += 1
            continue

        if(txt[i].islower()):
            if(txt[i - 3].isupper() and txt[i - 2].isupper() and txt[i - 1].isupper() and txt[i + 1].isupper() and txt[i + 2].isupper() and txt[i + 3].isupper() and not txt[i + 4].isupper() and not txt[i - 4].isupper()):
                result += txt[i]

        i += 1

    """
    #result.john(re.findall('[a-z][A-Z]{3}([a-z])[A-Z]{3}[a-z]', txt))
    result = ''.join(re.findall('[a-z][A-Z]{3}([a-z])[A-Z]{3}[a-z]', txt))
    print(result)

def c4():
    log = open("resources/c5_log.txt", 'a+')
    nothing = "12345"
    for i in range(500):
        url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=" + nothing
        response = urllib.request.urlopen(url)
        page = response.read().decode("utf-8")
        nothing = ''.join(re.findall("[0-9]", page))
    #num = re.match("[0-9]", page)
        txt = str(i) + " : " + nothing + "\n"
        log.write(txt)
        log.flush()
        print(txt)


c4()
